#ifndef _SOFTWARE_UART_H_
#define _SOFTWARE_UART_H_


#include "../../bitarray/BitArray.h"
#include "../../shifter/Shifter.h"



/*
	class : SoftwareUart
	desc : Software implementation of the uart protocol
*/
class SoftwareUart : public ProtocolImplementation
{
	public :
	//configuration for the software uart
	typedef struct SoftwareUART_CONFIG
	{
		unsigned char dataSize : 3;
		unsigned char stopNumber : 1;
		unsigned char polarity : 1; 
		unsigned char parity : 2;
		unsigned char finished : 1;
	}
	UartConfig;
	//enumerates io direction
	enum IODirection { Input, Output };
	//enumerates polarity
	enum Polarity { High=1, Low=0 };
	//enumerates parity
	enum Parity { NoParity, EvenParity, OddParity };
	//enumerates stops
	enum Stops { OneStop=0, TwoStop=1 };

	private :
		//configuration for the software uart
		UartConfig config;
		//in shifter used to be the transmission line
		Shifter inShifter;
		//out shifter used to be the receiver line.
		Shifter outShifter;
		//in bit for receiver line rx
		BitPointer inBit;
		//out bit for transmission line tx
		BitPointer outBit;
		//gets the newly received data as a unsigned char
		unsigned char get();
		//sets data to be transmitted.
		void set(unsigned char data);	
	
	public:
		//default constructor
		SoftwareUart();
		//constructor sets bits for input and output
		SoftwareUart(SoftwareUart::UartConfig c, BitPointer& in, 
				BitPointer& out);
		//configs the software uart
		void config();
		//initializes everything if needed depends on device if used.
		void init();
		//transmits data
		void transmitData();
		//receives data.
		void receiveData();
		//schedules if a transmit needs to happen again
		void scheduleTransmitInterrupt();
		//schedules if a receive needs to happen again
		void scheduleReceiveInterrupt();
		//runs the uart.
		void run();
};








#endif
